<!doctype html>
<html>
<head>
    <include file="public/head"/>
    <title>ThinkCMF插件 采集插件</title>
    <meta name="description" content="ThinkCMF插件 采集插件">
    <meta name="keywords" content="ThinkCMF插件 采集插件">
</head>
<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        
        <li class="dropdown">
            <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">{$site.sitename} <span class="caret"></span></a>
            <ul class="dropdown-menu">
            <li><a href="{:url('/plugin/crawler/admin_rule/index',array('crawler_site_id'=>$siteid))}">采集规则</a></li>
            <li><a href="{:url('/plugin/crawler/admin_rule/add',array('crawler_site_id'=>$siteid))}">添加规则</a></li>
            <li><a href="{:url('/plugin/crawler/admin_url/index',array('crawler_site_id'=>$siteid))}">采集列表</a></li>
            <li><a href="{:url('/plugin/crawler/admin_collection/index',array('crawler_site_id'=>$siteid))}">采集数据</a></li>
            <li role="separator" class="divider"></li>
            <li><a href="{:url('/plugin/crawler/admin_index/index')}">切换站点</a></li>
            </ul>
        </li>
        <li class="active"><a>添加列表</a></li>
    </ul>

    <form method="post" class="form-horizontal js-ajax-form margin-top-20" action="{:url('/plugin/crawler/admin_url/addPost/crawler_rule_id/'. $crawlerRule->id)}">
        <foreach name="parameters" item="vo" key="k">
        <div class="form-group">
            <label for="input-{$k}" class="col-sm-2 control-label"><span class="form-required">*</span>{$k}</label>
            <div class="col-md-1 col-sm-4">
                <input type="text" class="form-control" id="input-{$k}" name="parameters[{$k}]" data-key={$k} value="{$vo}">
            </div>
        </div>
        </foreach>
        <div class="form-group">
            <label for="textarea-listpath" class="col-sm-2 control-label">列表规则</label>
            <div class="col-md-6 col-sm-10">
                <input id="textarea-listpath" class="form-control" name="listpath" value='{$crawlerRule->listpath}' readonly />
                <p class="help-block">
                url中的中文会根据网站字符集自动转码；无需特殊设置<br>
                </p>
            </div>
        </div>
        <div class="form-group">
            <label for="textarea-listurl" class="col-sm-2 control-label"><span class="form-required">*</span>列表url</label>
            <div class="col-md-6 col-sm-10">
                <input class="form-control" id="textarea-listurl" name="listurl" value='{$crawlerRule->baseuri.$listurl}' readonly />
            </div>
        </div>
    
        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
                <input type='hidden' name='baseuri' id='input-baseuri' value='{$crawlerRule->baseuri}' />
                <button type="submit" class="btn btn-primary js-ajax-submit">{:lang('SAVE')}</button>
                <a class="btn btn-default" href="javascript:history.back(-1);">{:lang('BACK')}</a>
            </div>
        </div>
    </form>
   
</div>
<include file="public/scripts"/>
<script>
$(document).ready(function(){
    var baseuri = $('#input-baseuri').val();
    
    $('input[name^="parameters"]').change(function() {   
        var listpath = $('#textarea-listpath').val();

        $('input[name^="parameters"]').each(function() {
            var param_key = $(this).attr('data-key');
            var param_val = $(this).val();

            var patt = new RegExp("\{" + param_key + "(:[^\}]+)?\}", "i");
            listpath = listpath.replace(patt, param_val);
        })
        
        $('#textarea-listurl').val(baseuri + listpath);
    });

});
</script>
</body>
</html>